<?xml version="1.0" ?>
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:xi="http://www.w3.org/2003/XInclude"
   xmlns:fn="http://www.w3.org/2005/xpath-functions"
   xmlns="http://www.w3.org/2000/svg"
   >
   
   <xsl:variable name="resolution-x" select="1280" />
   <xsl:variable name="resolution-y" select="720" />
   <xsl:variable name="animation-duration" select="1" />
   <xsl:variable name="wait-duration" select="5" />
	
   <xsl:template match="/">
      <svg>
         <xsl:attribute name="width"><xsl:value-of select="$resolution-x"/></xsl:attribute>
         <xsl:attribute name="height"><xsl:value-of select="$resolution-y"/></xsl:attribute>
         <defs>
            <style type="text/css">
             @font-face {
                 font-family: eventfont;
                 src: url('event_font.otf');
             }
             </style>
            <linearGradient id="grad_lin1" x1="0%" y1="0%" x2="0%" y2="100%">
               <stop offset="0%" style="stop-color:rgb(32,139,202);stop-opacity:1" />
               <stop offset="100%" style="stop-color:rgb(27,126,183);stop-opacity:1" />
            </linearGradient>
         </defs>
         
         <rect x="0" y="0" width="100%" height="100%" stroke="black" fill="white" />
         <image x="40" y="15" width="383" height="25" xlink:href="logo.svg" />
         <rect x="0" y="60" width="100%" height="60" fill="url(#grad_lin1)" />
         <xsl:apply-templates />
      </svg>
	</xsl:template>
   
   <xsl:template match="event">
      <xsl:variable name="pos" select="count(preceding-sibling::*[name() = name(current())])" />
      <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
      <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
      
      <rect y="140" width="1080" height="450" fill="#41719c">
         <xsl:call-template name="animation">
           <xsl:with-param name="waitposition">100</xsl:with-param>
           <xsl:with-param name="childnumber"><xsl:value-of select="$pos" /></xsl:with-param>
         </xsl:call-template>
      </rect>
      <text x="1400" y="180" font-size="30" fill="white" style="font-family:'eventfont';">
         <xsl:value-of select="translate(name, $smallcase, $uppercase)" />
         
         <xsl:call-template name="animation">
           <xsl:with-param name="waitposition">120</xsl:with-param>
           <xsl:with-param name="childnumber"><xsl:value-of select="$pos" /></xsl:with-param>
         </xsl:call-template>
      </text>
      <foreignObject x="1400" y="220" width="600" height="1000" style="font-size:20px; font-family:'eventfont';color:white;">
         <xsl:attribute name="id">desc<xsl:value-of select="$pos" /></xsl:attribute>
         <html xmlns="http://www.w3.org/1999/xhtml">
            <body>
               <xsl:value-of select="description" /><br />
               <xsl:value-of select="concat('Von: ', from)" /><br />
               <xsl:value-of select="concat('Bis: ', to)" />
            </body>
         </html>
         
      </foreignObject>
      <xsl:call-template name="animation">
        <xsl:with-param name="waitposition">120</xsl:with-param>
        <xsl:with-param name="childnumber"><xsl:value-of select="$pos" /></xsl:with-param>
        <xsl:with-param name="elementId">#desc<xsl:value-of select="$pos" /></xsl:with-param>
      </xsl:call-template>
      <image y="170" width="400" height="300">
         <xsl:attribute name="xlink:href"><xsl:value-of select="picturePath"/></xsl:attribute>
         <xsl:call-template name="animation">
           <xsl:with-param name="waitposition">730</xsl:with-param>
           <xsl:with-param name="childnumber"><xsl:value-of select="$pos" /></xsl:with-param>
         </xsl:call-template>
      </image>
   </xsl:template>
   
   <xsl:template name="animation">
      <xsl:param name="waitposition" />
      <xsl:param name="childnumber" />
      <xsl:param name="elementId" />
      
      <xsl:variable name="time-offset" select="$childnumber * ($animation-duration+$wait-duration)" />
      
      <xsl:attribute name="x"><xsl:value-of select="$waitposition + $resolution-x"/></xsl:attribute>
      <animate attributeName="x">
         <xsl:choose>
            <xsl:when test="$elementId != ''">
               <xsl:attribute name="xlink:href"><xsl:value-of select="$elementId"/></xsl:attribute>
            </xsl:when>
         </xsl:choose>
         <xsl:attribute name="from"><xsl:value-of select="$waitposition + $resolution-x"/></xsl:attribute>
         <xsl:attribute name="to"><xsl:value-of select="$waitposition"/></xsl:attribute>
         <xsl:attribute name="begin"><xsl:value-of select="$time-offset"/>s</xsl:attribute>
         <xsl:attribute name="dur"><xsl:value-of select="$animation-duration"/>s</xsl:attribute>
      </animate>
      <animate attributeName="x">
         <xsl:choose>
            <xsl:when test="$elementId != ''">
               <xsl:attribute name="xlink:href"><xsl:value-of select="$elementId"/></xsl:attribute>
            </xsl:when>
         </xsl:choose>
         <xsl:attribute name="from"><xsl:value-of select="$waitposition"/></xsl:attribute>
         <xsl:attribute name="to"><xsl:value-of select="$waitposition"/></xsl:attribute>
         <xsl:attribute name="begin"><xsl:value-of select="$time-offset+$animation-duration"/>s</xsl:attribute>
         <xsl:attribute name="dur"><xsl:value-of select="$wait-duration"/>s</xsl:attribute>
      </animate>
      <animate attributeName="x">
         <xsl:choose>
            <xsl:when test="$elementId != ''">
               <xsl:attribute name="xlink:href"><xsl:value-of select="$elementId"/></xsl:attribute>
            </xsl:when>
         </xsl:choose>
         <xsl:attribute name="from"><xsl:value-of select="$waitposition"/></xsl:attribute>
         <xsl:attribute name="to"><xsl:value-of select="$waitposition - $resolution-x"/></xsl:attribute>
         <xsl:attribute name="begin"><xsl:value-of select="$time-offset+$animation-duration+$wait-duration"/>s</xsl:attribute>
         <xsl:attribute name="dur"><xsl:value-of select="$animation-duration"/>s</xsl:attribute>
      </animate>
   </xsl:template>
   
   <xsl:template match="xi:include[@href][@parse='xml' or not(@parse)]">
      <xsl:apply-templates select="document(@href)" />
   </xsl:template>
   
</xsl:stylesheet>
